// 全局请求封装
const base_url = 'http://localhost:8099'
// 请求超出时间
const timeout = 5000

// 需要修改token，和根据实际修改请求头
export default (params) => {
	let url = params.url;
	let method = params.method || "get";
	let data = params.data || {};
	let header = {}
	//这里拿取token uni.getStorageSync('authorization')
	if (uni.getStorageSync('authorization') != null) {
		header = {
			'Authorization': uni.getStorageSync('authorization') || null
		}
	}
	return new Promise((resolve,reject)=>{
		uni.request({
			url: base_url + url,
			method: method,
			header: header,
			data: data,
			timeout,
			success: (res) => {
				if (res.data.code == 0) {
					uni.showToast({
						title: res.data.msg,
						icon: "error",
						duration: 2000
					})
				} else {
					 resolve(res.data)
				}
		
			}
		})
	})
};
